package com.shiguiwu.springmybatis.app.config;

import com.mzt.logapi.beans.Operator;
import com.mzt.logapi.service.IOperatorGetService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/**
 * @description:
 * @author: stone
 * @date: Created by 2021/4/7 18:44
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springmybatis.config
 */
@Configuration
public class MyWebConfig extends WebMvcConfigurationSupport {

    @Value("${spring.mvc.static-path-pattern}")
    private String staticPathPattern;
    @Value("${spring.resources.static-locations}")
    private String staticLocations;

    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {

        String[] split = StringUtils.split(staticLocations, ",");

        assert split != null;
        registry.addResourceHandler(staticPathPattern,"/**").addResourceLocations(split);
    }

    /**
     * 日志操作人bean
     * @return
     */
    @Bean
    public IOperatorGetService operatorGetService() {
        return () -> new Operator("这里应该从threadLocal中取");
    }


    @Override
    protected void configurePathMatch(PathMatchConfigurer configurer) {
        //configurer.addPathPrefix("api", clazz -> clazz.isAnnotationPresent(RestController.class));

    }
}
